from flask import Flask
from inc import *
import sqlite3
from flask import g
app = Flask(__name__,static_folder=str(root/'web'),template_folder=str(root/'web'))
def make_dicts(cursor, row):
    return dict((cursor.description[idx][0], value)
                for idx, value in enumerate(row))
def get_db(keys=False):
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = sqlite3.connect(str(root/"yj.db"))
    if keys : db.row_factory = make_dicts
    return db
def query_db(query, args=(), one=False,keys=False):
    cur = get_db(keys).execute(query, args)
    rv = cur.fetchall()
    cur.close()
    return (rv[0] if rv else None) if one else rv
@app.teardown_appcontext
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.close()
@app.errorhandler(500)
def internal_server_error(e):
    return "error"